package com.ruoyi.gqgl.rdjh.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gqgl.rdjh.domain.Rdjh;
import com.ruoyi.gqgl.rdjh.domain.Rdxmsx;
import com.ruoyi.gqgl.rdjh.service.IRdjhService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;

/**
 * 高企管理认定计划Controller
 *
 * @author huacai
 * @date 2025-01-23
 */
@RestController
@RequestMapping("/gqgl/rdjh")
public class RdjhController extends BaseController {
    @Resource
    private IRdjhService rdjhService;

    /**
     * 查询高企管理认定计划列表
     */
    @PreAuthorize("@ss.hasPermi('gqgl:rdjh:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rdjh rdjh) {
        startPage();
        List<Rdjh> list = rdjhService.selectRdjhList(rdjh);
        return getDataTable(list);
    }

    /**
     * 导出高企管理认定计划列表
     */
    @PreAuthorize("@ss.hasPermi('gqgl:rdjh:export')")
    @Log(title = "高企管理认定计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rdjh rdjh) {
        List<Rdjh> list = rdjhService.selectRdjhList(rdjh);
        ExcelUtil<Rdjh> util = new ExcelUtil<Rdjh>(Rdjh.class);
        util.exportExcel(response, list, "高企管理认定计划数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<Rdjh> util = new ExcelUtil<Rdjh>(Rdjh.class);
        util.importTemplateExcel(response, "高企管理认定计划数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "高企管理认定计划", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('gqgl:rdjh:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<Rdjh> util = new ExcelUtil<Rdjh>(Rdjh.class);
        InputStream inputStream = file.getInputStream();
        List<Rdjh> list = util.importExcel(inputStream);
        inputStream.close();
        int count = rdjhService.batchInsertRdjh(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取高企管理认定计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('gqgl:rdjh:query')")
    @GetMapping(value = "/{rdjhId}")
    public AjaxResult getInfo(@PathVariable("rdjhId") Integer rdjhId) {
        return success(rdjhService.selectRdjhByRdjhId(rdjhId));
    }

    /**
     * 新增高企管理认定计划
     */
    @PreAuthorize("@ss.hasPermi('gqgl:rdjh:add')")
    @Log(title = "高企管理认定计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rdjh rdjh) {
        return toAjax(rdjhService.insertRdjh(rdjh));
    }

    /**
     * 修改高企管理认定计划
     */
    @PreAuthorize("@ss.hasPermi('gqgl:rdjh:edit')")
    @Log(title = "高企管理认定计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rdjh rdjh) {
        return toAjax(rdjhService.updateRdjh(rdjh));
    }

    /**
     * 删除高企管理认定计划
     */
    @PreAuthorize("@ss.hasPermi('gqgl:rdjh:remove')")
    @Log(title = "高企管理认定计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{rdjhIds}")
    public AjaxResult remove(@PathVariable Integer[] rdjhIds) {
        return toAjax(rdjhService.deleteRdjhByRdjhIds(rdjhIds));
    }

    /**
     * 查询认定项目筛选列表
     */
    @GetMapping("/selectRdxmsxList")
    public TableDataInfo selectRdxmsxList(Rdxmsx rdxmsx) {
        startPage();
        List<Rdxmsx> list = rdjhService.selectRdxmsxList(rdxmsx);
        return getDataTable(list);
    }

}
